package com.homegoods.home.presenters;

import android.util.Log;

import com.alibaba.fastjson.JSON;
import com.homegoods.area.model.SubModelList;
import com.homegoods.goods.adapter.FlexBoxAdapter;
import com.homegoods.home.HomeApiUtils;
import com.homegoods.home.model.NewProductModel;
import com.kedll.library.adapter.MultiTypeAdapter;
import com.kedll.library.mvp.AbstractRefreshPresenter;
import com.kedll.library.mvp.RefreshingView;
import com.kedll.library.util.MyUtils;

import java.util.List;
import java.util.Random;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

/**
 * @author QiQi
 */
public class MoreNewProductPresenter extends AbstractRefreshPresenter<RefreshingView> {
    private String childSid;
    private int pos = 1;

    public MoreNewProductPresenter(RefreshingView view, String childSid) {
        super(view);
        this.childSid = childSid;
    }

    @Override
    protected void fetchData(boolean isLoadMore) {
        if (isLoadMore) {
            pos++;
        }
        HomeApiUtils.HomeComdiyList(pos, 10, subModelList -> {
            List<NewProductModel> list = JSON.parseArray(subModelList.getItems(), NewProductModel.class);
            if (list != null) {
                MoreNewProductPresenter.this.parserData(isLoadMore, list);
            }
        }, throwable -> {
        });
    }

    @Override
    public MultiTypeAdapter getAdapter() {
        //modify for shibo.zheng 19/06/26
        adapter = new FlexBoxAdapter(mView.getContext(), 1, MyUtils.dp2px(24));
        return adapter;
    }

}